package com.zkyc.framework.website.controller;

import com.zkyc.framework.common.Enum.LogType;
import com.zkyc.framework.common.annotation.Log;
import com.zkyc.framework.common.exception.ResultCode;
import com.zkyc.framework.common.pojo.Moudle;
import com.zkyc.framework.common.vo.ResultVO;
import com.zkyc.framework.website.service.MoudleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Moudle)表控制层
 *
 * @author libingchuan
 * @since 2022-05-24 16:33:26
 */
@RestController
@RequestMapping("moudle")
public class MoudleController {
    /**
     * 服务对象
     */
    @Resource
    private MoudleService moudleService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("list")
    public ResultVO queryList(Integer columnType,Integer websiteId) {
        return moudleService.queryList(columnType,websiteId);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/query/{id}")
    public ResultVO queryById(@PathVariable("id") Integer id) {
        Moudle moudle = moudleService.queryById(id);
        if(moudle == null){
            return ResultVO.fail(ResultCode.SERVE_ERROR);
        }
        return ResultVO.data(moudle);
    }

    /**
     * 新增数据
     *
     * @param moudle 实体
     * @return 新增结果
     */
    @PostMapping("save")
    public ResultVO add(@RequestBody Moudle moudle) {
        return moudleService.insert(moudle);
    }

    /**
     * 编辑数据
     *
     * @param moudle 实体
     * @return 编辑结果
     */
    @PostMapping("edit")
    public ResultVO edit(@RequestBody Moudle moudle) {
        return moudleService.update(moudle);
    }

    /**
     * 编辑模块信息
     *
     * @param moudle 实体
     * @return 编辑结果
     */
    @Log(type = LogType.修改模块)
    @PostMapping("editName")
    public ResultVO editeditName(@RequestBody Moudle moudle) {
        return moudleService.updateName(moudle);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("delete")
    public ResultVO deleteById(Integer id) {
        return moudleService.deleteById(id);
    }

    /**
     *
     * 根据moudleId获取数据
     * @param id 主键
     */
    @GetMapping("queryMoudleData")
    public ResultVO queryMoudleData(Integer id) {
        return moudleService.queryMoudleData(id);
    }

    @GetMapping("routerList")
    public  ResultVO routerList(){
        return moudleService.getRouterList();
    }


    @GetMapping("treeList")
    public  ResultVO treeList(){
        return moudleService.getTreeList();
    }

    @GetMapping("recommendMoudle")
    public  ResultVO recommendMoudle(String columnName){
        return moudleService.recommendMoudle(columnName);
    }

}

